package com.tomato.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tomato.order.VO.ResultVO;
import com.tomato.order.entity.Support;
import com.tomato.order.mapper.SupportMapper;
import com.tomato.order.util.R;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/support")
public class SupportController {
    @Resource
    private SupportMapper supportMapper;
    @RequestMapping("/list")
    public List list(){
        return supportMapper.selectList(new QueryWrapper<Support>().orderByDesc("id"));
    }
    @RequestMapping("/create")
    public ResultVO create(Support support){
        int result=supportMapper.insert(support);
        if (result==1){
            return R.success("添加成功！");
        }else{
            return R.error(1,"添加失败！");
        }
    }
    @RequestMapping("/delete")
    public ResultVO delete(@RequestParam("id")String id){
        int result=supportMapper.delete(new QueryWrapper<Support>().eq("id",id));
        if (result==1){
            return R.success("删除成功！");
        }else{
            return R.error(1,"删除失败！");
        }
    }
}
